package com.ruicar.afs.cloud.afscase.approvetask.controller;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruicar.afs.cloud.afscase.approvetask.condition.WorkTaskPoolCondition;
import com.ruicar.afs.cloud.afscase.approvetask.entity.ApproveTeleRecord;
import com.ruicar.afs.cloud.afscase.approvetask.service.ApproveTeleRecordService;
import com.ruicar.afs.cloud.afscase.approvetask.vo.TeleRecordVo;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>Description: </p>
 *
 * @author ZC.GUO
 * @version 1.0
 * @date create on 2020-05-31 17:51
 */
@Slf4j
@RestController
@AllArgsConstructor
@Api("信审电话")
@RequestMapping("/telRecord")
public class TelRecordController {

    private ApproveTeleRecordService approveTeleRecordService;

    @PostMapping(value = "/queryRecordListByApplyNo")
    @ApiOperation(value = "根据申请编号查询电话记录")
    public IResponse<List<TeleRecordVo>> queryRecordListByApplyNo(@ModelAttribute WorkTaskPoolCondition workTaskPoolCondition) {
        List<TeleRecordVo> teleRecordVoList = new ArrayList<>();
        List<ApproveTeleRecord> approveTeleRecordList = approveTeleRecordService.list(Wrappers.<ApproveTeleRecord>query().lambda()
                .eq(ApproveTeleRecord::getApplyNo, workTaskPoolCondition.getApplyNo())
        );
        if (CollectionUtils.isNotEmpty(approveTeleRecordList)) {
            approveTeleRecordList.forEach(approveTeleRecord -> {
                TeleRecordVo teleRecordVo = new TeleRecordVo();
                BeanUtils.copyProperties(approveTeleRecord, teleRecordVo);
                teleRecordVoList.add(teleRecordVo);
            });
        }

        return IResponse.success(teleRecordVoList);
    }
}
